package com.yeyks.controller.activity;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeyks.activity.dal.domain.ActivityNodeUserRecord;
import com.yeyks.activity.service.ActivityNodeUserRecordService;
import com.yeyks.common.ajax.AjaxResponseBody;
import com.yeyks.common.result.activity.ActivityCardStatResult;
import com.yeyks.common.result.activity.ActivityNewUserTaskStatResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "新人任务活动统计")
@RestController
@Slf4j
@RequestMapping("/new/user/task")
public class ActivityNewTaskStatController {

    @Autowired
    private ActivityNodeUserRecordService activityNodeUserRecordService;

    @ApiOperation(value = "v4.3 --> 活动总统计", response = ActivityNewUserTaskStatResult.class)
    @PostMapping(value = "/total")
    public AjaxResponseBody<ActivityNewUserTaskStatResult> total() {
        Integer overTwo = activityNodeUserRecordService.count(new QueryWrapper<ActivityNodeUserRecord>().eq(ActivityNodeUserRecord.ACTIVITY_CODE, "NewUserTask").eq(ActivityNodeUserRecord.NODE, "over_two"));
        Integer overThree = activityNodeUserRecordService.count(new QueryWrapper<ActivityNodeUserRecord>().eq(ActivityNodeUserRecord.ACTIVITY_CODE, "NewUserTask").eq(ActivityNodeUserRecord.NODE, "over_three"));
        Integer overFour = activityNodeUserRecordService.count(new QueryWrapper<ActivityNodeUserRecord>().eq(ActivityNodeUserRecord.ACTIVITY_CODE, "NewUserTask").eq(ActivityNodeUserRecord.NODE, "over_four"));
        return AjaxResponseBody.success(new ActivityNewUserTaskStatResult(overTwo, overThree, overFour));
    }

    @ApiOperation(value = "v4.3 --> 佣金领取人数", response = ActivityCardStatResult.class)
    @PostMapping(value = "/get/total")
    public AjaxResponseBody<List<ActivityCardStatResult>> getTotal() {
        //根据activity_code和node查询
        List<ActivityCardStatResult> activityCardStatResults = activityNodeUserRecordService.stat("NewUserTask", "over");
        return AjaxResponseBody.success(activityCardStatResults);
    }

    @ApiOperation(value = "v4.3 --> 任务完成人数", response = ActivityCardStatResult.class)
    @PostMapping(value = "/complete/total")
    public AjaxResponseBody<List<ActivityCardStatResult>> completeTotal() {
        //根据activity_code和node查询
        List<ActivityCardStatResult> activityCardStatResults = activityNodeUserRecordService.stat("NewUserTask", "finish");
        return AjaxResponseBody.success(activityCardStatResults);
    }

}
